<notdefined name="W_UPLOADIER">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Js/Webuploader/webuploader.css" />
<script type="text/javascript" src="__PUBLIC__/Js/Webuploader/webuploader.js"></script>
<define name="W_UPLOADIER" value="1" />
</notdefined>

<div id="{$name}" class="UploaderImgBox">
    <empty name="value">
    <img id="{$name}_thumb" src="__PUBLIC__/Img/thumb.png">
    <else />
    <img id="{$name}_thumb" src="{$value}">
    </empty>
    <a id="{$name}_pick" class="btn" href="javascript:;">上传文件</a><a id="{$name}_remove" class="btn" href="javascript:;">取消文件</a>
    <input id="{$name}_input" type="hidden" name="{$name}" value="{$value}">
</div>

<script type="text/javascript">
(function($){
    var id='{$name}';
    var Wu = WebUploader.create({
        swf: "__PUBLIC__/Js/Webuploader/Uploader.swf",
        server:"{:U('Admin/Index/widget/name/uploader')}",
        pick: {
            id:'#'+id+'_pick',
            multiple:false,
        },
        auto:true,
        thumb:false,
        compress:false,
        accept: {
            title: 'Images',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/*'
        },
        formData:{
            session_id : "{:session_id()}",
            //动态配置参数
            <foreach name="config" item="v" key="k">
            {$k}:"{$v}",
            </foreach>
        }
    });
    Wu.on( 'uploadProgress', function( file, percentage ) {
        var $box = $('#'+id),
            $percent = $box.find('.progress .progress-bar');
        // 避免重复创建
        if ( !$percent.length ) {
            $percent = $('<div class="progress progress-striped active">' +
              '<div class="progress-bar" role="progressbar" style="width: 0%">' +
              '</div>' +
            '</div>').appendTo( $box ).find('.progress-bar');
        }
        $percent.css( 'width', percentage * 100 + '%' );
    });
    Wu.on( 'uploadComplete', function( file,data ) {
        $('#'+id).find('.progress').remove();
    });
    Wu.on( 'uploadSuccess', function( file ,response) {
        $('#'+id+'_input').val(response.url);
        $('#'+id+'_thumb').attr('src',response.url);
        Wu.reset();
    });
    $('#'+id+'_remove').click(function(e) {
        $('#'+id+'_input').val('');
        $('#'+id+'_thumb').attr('src',"__PUBLIC__/Img/thumb.png");
    });

})(jQuery);

</script>